var e = require("../../../../@babel/runtime/helpers/regeneratorRuntime"),
  t = require("../../../../@babel/runtime/helpers/objectSpread2"),
  a = require("../../../../@babel/runtime/helpers/slicedToArray"),
  n = require("../../../../@babel/runtime/helpers/asyncToGenerator"),
  r = require("../../../../utils/helper/common/index");
Component({
  componentPage: {
    onPullDownRefresh: function () {
      this.onRefresh(1).finally((function () {
        wx.stopPullDownRefresh()
      }))
    },
    onReachBottom: function () {
      this.data.hasMore || this.data.noData || this.onRefresh(this.page + 1)
    }
  },
  data: {
    firstLoaded: !1,
    list: [],
    loading: !1,
    noData: !1,
    hasMore: !1
  },
  methods: {
    onRefresh: function () {
      var r = arguments,
        o = this;
      return n(e().mark((function n() {
        var i, s, u, c, l, d, h, f, p, m, D;
        return e().wrap((function (e) {
          for (;;) switch (e.prev = e.next) {
            case 0:
              return i = r.length > 0 && void 0 !== r[0] ? r[0] : 1, s = r.length > 1 ? r[1] : void 0, o.page = i, 1 !== i && o.setData({
                loading: !0
              }), e.prev = 3, u = t(t({}, o.parames), {}, {
                page: o.page || i,
                page_size: 15,
                source: "XCX"
              }, s), e.next = 7, $.request["GET/v2/user/contacted"](u);
            case 7:
              if (c = e.sent, l = a(c, 1), d = l[0], h = d.content, f = h.list, p = h.last_id, f = f.map((function (e) {
                  return t(t({}, e), {}, {
                    machine: t(t({}, e.machine), {}, {
                      timestamp: e.time
                    })
                  })
                })), 1 !== i || 0 !== f.length) {
                e.next = 13;
                break
              }
              return e.abrupt("return", void o.setData({
                noData: !0,
                list: []
              }));
            case 13:
              if (p ? o.setData({
                  hasMore: !1
                }) : o.setData({
                  hasMore: !0
                }), 1 !== i) {
                e.next = 15;
                break
              }
              return e.abrupt("return", (o.setData({
                list: f.slice(0, 5),
                noData: !1
              }), void setTimeout((function () {
                o.setData({
                  list: o.data.list.concat(f.slice(5)),
                  noData: !1
                })
              }), 200)));
            case 15:
              m = o.data.list.length, D = f.reduce((function (e, t, a) {
                return o.data.list.find((function (e) {
                  return (null == e ? void 0 : e.uu) === t.uu
                })) ? e["list[".concat(a + m, "]")] = {} : e["list[".concat(a + m, "]")] = t, e
              }), {
                noData: !1
              }), o.setData(D);
            case 17:
              return e.prev = 17, o.setData({
                loading: !1
              }), !o.data.firstLoaded && setTimeout((function () {
                return o.setData({
                  firstLoaded: !0
                })
              }), 150), e.finish(17);
            case 20:
            case "end":
              return e.stop()
          }
        }), n, null, [
          [3, , 17, 20]
        ])
      })))()
    },
    onButtonTap: function (e) {
      var t = e.target.dataset.item;
      (0, r.getPhone)({
        id: t.uu,
        mode: t.mode
      }).then((function (e) {
        200 == e.code && (0, r.callPhone)(e.content)
      }))
    }
  }
});